package com.ts.content.Job;

import com.ts.content.constants.RedisKey;
import com.ts.content.entity.TopicEntity;
import com.ts.content.service.TopicService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**查询热门圈子的定时任务
 * @author ljb
 * @date 2023/3/7 14:25
 */
@EnableScheduling
@Component
@Slf4j
@Data
public class HotTpoicJob{
    @Autowired
    private TopicService topicService;

    @Autowired
    private RedisTemplate redisTemplate;

    private Integer count;

//    @Scheduled(cron = "* 0/10 * * * ?")
    public void searchHotTopic(){
        //1.先查数据库
        List<TopicEntity> hotTopiclist = topicService.getHotTopic(count);
        //2.放进redis
        redisTemplate.opsForSet().add(RedisKey.JOB_SEARCH_HOTTOPIC_KEY,hotTopiclist);

    }
}
